import {BpmnNode} from "/@/views/flow/design/component/property-panel/ts/node/BpmnNode";
import UserTask from '../../../panel/UserTask.vue'

/**
 * 用户任务节点
 */
export class UserTaskNode extends BpmnNode{
    private businessObject;
    private component;

    constructor() {
        super();
        this.component = UserTask
    }

    async setProperties(e,object,moddle,modeling) {
        let obj = {} as any
        let extensionItems = [] as any[]
        for (const key in object) {
            if(key.startsWith('_')){
                const extensionItem = await moddle.create("camunda:Properties",{
                    name: key.substring(1),
                    value: JSON.stringify(object[key])
                })
                extensionItems.push(extensionItem)
            }else{
                obj[key] = object[key]
            }
        }
        const extensions = await moddle.create('bpmn:ExtensionElements',{values:extensionItems})
        obj.extensionElements = extensions
        modeling.updateProperties(e.element,obj)
    }

    nodeClick(bpmnViewerValue: any,e: any) {
        this.businessObject = e.element.businessObject
        const modeling = bpmnViewerValue.get('modeling')
        const moddle = bpmnViewerValue.get("moddle")
        if(this.propertyPanelRef){
            this.propertyPanelRef.value.init(this.businessObject,this.component,async (object: any)=>{
                this.setProperties(e,object,moddle,modeling);
            })
        }
    }

    nodeChange(bpmnViewerValue: any, e: any) {
    }

    nodeCreate(bpmnViewerValue: any, e: any){

    }



}